#include "Connection.h"
#include "IBuffer.h"
#include "Threadpool.h"
#include "IEmpacter.h"
#include "Guest.h"
#include "IMutex.h"
#include "IBuffer.h"
#include "IEvent.h"

class Client
{
public:
	Client(IEmpacter *empacter, IBuffer *buffer, unsigned int bufferReadSize);
	~Client();
	int				Disconnect();
	int				GetId();
	int				Connect(std::string adress, int port);
	bool			IsConnected();

	unsigned int			SendBuffer(void* data, unsigned int size);
	static void				SendData(void* client);

private:
	enum ReceiveState
	{
		HEADER,
		PACKET
	};
	IEmpacter*		_empacter;
	IBuffer*		_buffer;
	unsigned int	_bufferReadSize;
	int				_id;
	unsigned int	_availableToSend;
	bool			_sendLoop;
	bool			_isConnected;
	Network::Guest* _connection;
	static void		SelectReceive(void* client);
	int				Authentificate();


	IBuffer*				_buffSend;
	IMutex*					_lockSend;
	IEvent*					_eventBuffer;
	IEvent*					_eventDestructor;
};
